<cfcomponent extends="AbsDAO" output="false">

	<cffunction name="create" access="public" returntype="Numeric" output="false">
		<cfargument name="comment" type="it.millemultimedia.easyBlog.model.Comment" required="true" />	
		<cfset var qry = "" />	
		<cfset var id = 0 />
		
		<cftransaction>
		
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
				INSERT INTO Comment
				(
					idpost,status,postdate,uuid,
				name,email,website,comment
				)
				VALUES
				(
					<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidPost()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_BIT" value="#arguments.comment.getstatus()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#arguments.comment.getpostdate()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getuuid()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getname()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getemail()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getwebsite()#" null="false" />,
				<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.comment.getcomment()#" null="false" />
				)
			</cfquery>
			
			<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT MAX(idcomment) AS id
			FROM Comment
			</cfquery>
			
			<cfset id = qry.id />
		
		</cftransaction>

		<cfreturn id />
	</cffunction>
	
	<cffunction name="read" access="public" returntype="Query" output="false">
		<cfargument name="comment" type="it.millemultimedia.easyBlog.model.Comment" required="true" />
		<cfset var qry="" />
		
		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT idcomment,idpost,status,postdate,uuid,
					name,email,website,comment
			FROM Comment
			WHERE idcomment = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidComment()#" null="false" />
		</cfquery>
		
		<cfreturn qry />
	</cffunction>
	
	<cffunction name="update" access="public" returntype="void" output="false">
		<cfargument name="comment" type="it.millemultimedia.easyBlog.model.Comment" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			UPDATE Comment
			SET idpost = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidPost()#" null="false" />,
				status = <cfqueryparam cfsqltype="CF_SQL_BIT" value="#arguments.comment.getstatus()#" null="false" />,
				comment = <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.comment.getcomment()#" null="false" />
			WHERE idcomment = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidComment()#" null="false" />
		</cfquery>

	</cffunction>
	
	<cffunction name="delete" access="public" returntype="void" output="false">
		<cfargument name="comment" type="it.millemultimedia.easyBlog.model.Comment" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			DELETE FROM Comment
			WHERE idcomment = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidComment()#" null="false" />
		</cfquery>
	</cffunction>
	
	
	<cffunction name="list" access="public" returntype="Query" output="false">
		<cfargument name="comment" type="it.millemultimedia.easyBlog.model.Comment" required="true" />
		
		<cfset var qry="" />

		<cfquery name="qry" datasource="#getDataSource().getName()#" username="#getDataSource().getUserName()#" password="#getDataSource().getPassword()#">
			SELECT * 
			FROM Comment
			WHERE idComment is NOT NULL 
			<cfif !isNull( arguments.comment.getidComment() ) >
			AND  idComment = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidComment()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getidPost() ) >
			AND  idPost = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.comment.getidPost()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getstatus() ) >
			AND  status = <cfqueryparam cfsqltype="CF_SQL_BIT" value="#arguments.comment.getstatus()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getpostdate() ) >
			AND  postdate = <cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#arguments.comment.getpostdate()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getuuid() ) >
			AND  uuid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getuuid()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getname() ) >
			AND  name = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getname()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getemail() ) >
			AND  email = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getemail()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getwebsite() ) >
			AND  website = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.comment.getwebsite()#" null="false" />
			</cfif>
			
				
			<cfif !isNull( arguments.comment.getcomment() ) >
			AND  comment = <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#arguments.comment.getcomment()#" null="false" />
			</cfif>
			
		</cfquery>
		
		<cfreturn qry/>
	</cffunction>

</cfcomponent>
